<template>
  <j-modal
    :title="title"
    :width="1200"
    :visible="visible"
    :maskClosable="false"
    @close="close"
    :destroyOnClose="true"
    :dialogStyle="{ top: '50px' }"
  >
    <template slot="footer">
      <a-button type="primary" @click="close">确定</a-button>
    </template>
    <a-form layout="inline">
      <a-row :gutter="24">
        <a-col :span="24">
          <div style="margin: 0 auto" :class="{ isCheck: isCheck }">
            <a-row :gutter="24">
              <a-col :md="8" :sm="24" style="height: 60vh; overflow: auto">
                <AuditTreeTable ref="AuditDepart" @selectedRow="updateQueryParam" />
              </a-col>
              <a-col :md="24 - 8" :sm="24" style="height: 60vh; overflow-x: hidden; overflow-y: auto">
                <div class="table-page-search-wrapper">
                  <a-form-model layout="inline" :model="queryParam">
                    <a-row :gutter="10">
                      <a-col :md="17" :sm="12">
                        <a-form-model-item label="" prop="assName" style="margin-left: 8px">
                          <a-input placeholder="请输入项目名称" v-model="queryParam.assName"></a-input>
                        </a-form-model-item>
                      </a-col>

                      <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
                        <a-col :md="6" :sm="24">
                          <a-button type="primary" @click="searchQuery" icon="search" style="margin-left: 18px"
                            >查询</a-button
                          >
                          <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px"
                            >清除条件</a-button
                          >
                        </a-col>
                      </span>
                    </a-row>
                  </a-form-model>
                </div>
                <a-table
                  :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: 'radio' }"
                  ref="table"
                  size="middle"
                  bordered
                  rowKey="id"
                  :columns="columns"
                  :dataSource="dataSource"
                  :pagination="ipagination"
                  :loading="loading"
                  @change="handleTableChange"
                >
                  <!-- <span slot="action" slot-scope="text, record">
                    <a @click="">详情</a>
                  </span> -->
                </a-table>
              </a-col>
            </a-row>
          </div>
        </a-col>
      </a-row>
    </a-form>
    <!-- table区域-end -->
  </j-modal>
</template>
<script>
import AuditTreeTable from '@/views/sj/sjmxgl/cwzb/components/AuditTreeTable'
import columns from './indexColumns'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import * as lodash from 'lodash'
import { httpAction, getAction, postAction, deleteAction } from '@/api/manage'

export default {
  name: 'selectModel',
  mixins: [JeecgListMixin],
  prop: ['payload'],
  components: { AuditTreeTable },
  data() {
    return {
      modelType: '',
      title: '查询条件',
      labelCol: { span: 4 },
      wrapperCol: { span: 18 },
      visible: false,
      isCheck: false,
      queryParam: {
        orgId: undefined,
        assName: undefined
      },
      disableMixinCreated: true,
      columns: columns(this),
      selectedRowKeys: [],
      selectedRows: [],
      selectedKeys: [],
      treeData: [],
      url: {
        list: '/sjmx/queryProList',
      }
    }
  },
  methods: {
    searchReset() {
      this.queryParam.assName = ''
      this.loadData(1)
    },
    searchQuery() {
      this.loadData(1)
    },
    handleTreeSelect(selectedKeys, event) {
      this.queryParam = this.$options.data().queryParam
      this.selectedKeys = [selectedKeys[0]]
      this.queryParam.modelId = event.node.dataRef.key
      this.queryParam.modelName = event.node.dataRef.title
      this.modelType = event.node.dataRef.modelType
    },
    updateQueryParam(checkRow) {
      this.queryParam.orgName = checkRow.departName
      this.queryParam.orgId = checkRow.id
      this.loadData(1)
    },
    onSelectChange(selectedRowKeys, data) {
      console.log('selectedRowKeys changed: ', selectedRowKeys)
      console.log('selectedRowKeys changed: ',data[0])
      this.selectedRowKeys = selectedRowKeys
      this.queryParam.proId = data[0].proId
      this.queryParam.proName = data[0].proName
    },

    edit(record) {
      this.dataSource = []
      this.selectedRowKeys = []
      this.modelType = ''
      if (record) {
        this.queryParam = record
        this.visible = true
      } else {
        this.visible = true
      }
      this.$nextTick(() => {
        this.$refs.AuditDepart.show()
      })
    },
    close(isSubmit) {
      this.dataSource = []
      if (isSubmit) {
        this.$emit('getdata', this.queryParam)
        this.visible = false
      } else {
        this.visible = false
      }
      this.queryParam = {}
    }
  }
}
</script>
<style lang="less" scoped></style>
